package com.wq.feign.consumer.controller;

import com.wq.feign.api.clients.ProductProviderClient;
import com.wq.feign.api.domain.Result;
import com.wq.feign.api.domain.request.ProductReq;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
public class ProductConsumerController {

    @Resource
    RestTemplate restTemplate;

    @Resource
    private ProductProviderClient productProviderClient;

    public static String url = "http://localhost:8081/";

    /**
     * 查询
     * @param id
     * @return
     */
    @GetMapping("product/consumer/get2/{id}")
    public Result selectById2(@PathVariable("id") Long id){

        return restTemplate.getForObject(url+"product/provider/get/"+id, Result.class);
    }

    /**
     * 查询
     * @param id
     * @return
     */
    @GetMapping("product/consumer/get/{id}")
    public Result selectById(@PathVariable("id") Long id){
        Result result = productProviderClient.selectById(id);
        return result;
    }

    @GetMapping("product/consumer/update")
    public Result updateProduct() {
        ProductReq productReq = new ProductReq();
        productReq.setId(1L);
        productReq.setName("小米11");
        return productProviderClient.updateProduct(productReq);
    }

}


